
package com.epam.android.training.day7.task1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Main activity of the test application which starts and stops
 * {@link SimpleService}.
 * 
 * @author Anton Novikau
 */
public class MainActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    addStartServiceButtonAction();

    addStopServiceButtonAction();
  }

  private void addStartServiceButtonAction() {
    Button startButton = (Button) findViewById(R.id.start_service);
    startButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        startService(new Intent(MainActivity.this, SimpleService.class));
      }
    });
  }

  private void addStopServiceButtonAction() {
    Button stopButton = (Button) findViewById(R.id.stop_service);
    stopButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        stopService(new Intent(MainActivity.this, SimpleService.class));
      }
    });
  }
}
